﻿#pragma once
#include"Hashtable.h"
namespace L
{
	template<class K, class V, class Hash = HashFunc<K>>
	class unordered_map
	{
		struct MapKeyOfT
		{
			const K& operator()(const pair<K, V>& kv)
			{
				return kv.first;
			}
		};
	public:
		typedef typename hash_bucket::Hashtable<K, pair<const K, V>, MapKeyOfT, Hash>::iterator iterator;
		iterator begin()
		{
			return _ht.begin();
		}

		iterator end()
		{
			return _ht.end();
		}

		bool insert(const pair<K, V>& kv)
		{
			return _ht.Insert(kv);
		}
	private:
		hash_bucket::Hashtable<K, pair<const K, V>, MapKeyOfT, Hash> _ht;
	};
	void test_map1()
	{
		unordered_map<string, string> dict;
		dict.insert(make_pair("sort", "1"));
		dict.insert(make_pair("left", "2"));
		dict.insert(make_pair("right", "3"));

		
		unordered_map<string,string>::iterator it = dict.begin();
		while (it != dict.end())
		{
			cout<<(*it).first<<" " << (*it).second<<endl;
			//cout << *it.first << " " << *it.second << endl;
			/*pair<string, string> t=*it;
			cout << t.first << " " << t.second<<endl;*/
			++it;
		}
		cout << endl;
		//for (auto& kv : dict)
		//{
		//	//kv.first += 'x';
		//	kv.second += 'y';

		//	cout << kv.first << ":" << kv.second << endl;
		//}
	}
	
}
